package com.wipz.eoa.iphone.officedocument;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.toft.core2.dao.SqlUtils;
import com.toft.widgets.workflow.model.CompleteTaskResult;
import com.toft.widgets.workflow.utils.ConstantUtil;
import com.wipz.eoa.iphone.businessProcess.BusinessCoreServices;

/**
 * 收文管理业务接口实现类
 * @author 张涛
 * @date 2012-2-10
 */
public class ReceiveDocumentServiceImpl extends BusinessCoreServices implements
		IReceiveDocumentService {

	@SuppressWarnings("unchecked")
	@Override
	public List queryAll(Map params) {
		
		return super.queryList("receivedocument.queryAll", params);
	}

	@Override
	public List query(Map params) {

		return super.queryList("receivedocument.query", params);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Map view(Map params) {
		return (Map) super.queryOne("receivedocument.queryById", params);
	}

	@Override
	public Map bxSubmit(Map param) {
		String userCode = (String) param.get("COMMITERCODE");
		// 任务唯一标识taskId
		String taskId = (String) param.get("taskId");
		// 处理意见
		String commentContent = (String) param.get("comment");
		// 流向
		String transition = (String) param.get("transition");
		// 处理类型
		String typeaccept = (String) param.get("pass");
		
		String uuitId = (String) param.get("uuitId");
		
		String id = (String) param.get("id");
		
		boolean pass = typeaccept == "true" ? true : false;
		Map variable = new HashMap();
		variable.put(ConstantUtil.TASK_COMMNET_TYPE,
						ConstantUtil.APPROVE_OPERATION_PASS.equals(typeaccept) ? ConstantUtil.TASK_COMMNET_TYPE_ACCEPT
								: ConstantUtil.TASK_COMMNET_TYPE_REFUSE); // 意见类型
		variable.put(ConstantUtil.TASK_COMMENT_CONTENT, commentContent); // 意见内容
		CompleteTaskResult result = this.complete(userCode, taskId, transition,
				variable, pass,uuitId);
		if(result == null) {
			return null;
		}
		String process_status = "1";
		if (result.isEnded()) {
			process_status = "2";
		} else if (result.isBack()) {
			process_status = "4";
		}
		String nextOne = result.getNextOperators();
		if("".equals(nextOne)||result.isEnded())
			nextOne = "审批结束";
		Map map = new HashMap();
		map.put("ID", id);
		map.put("PROCESS_STATUS", process_status);
		super.update("receivedocument.changeprocessstatus", map);
		map.put("nextOperators", nextOne);
		super.update("receivedocument.getnext", map);
		//this.getContext().addAttribute("result", result);
		Map resultMap = new HashMap();
		resultMap.put("ended", result.isEnded()+"");
		resultMap.put("back", result.isBack()+"");
		resultMap.put("nextOperators",result.getNextOperators());
		return resultMap;

	}

}
